<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="user.name">
    </div>
    <script>
        let app = new Vue({
            el: "#app",
            data: {
                message: "",
                user: {
                    name: ""
                }
            },
            watch: {
                //让侦听器自动触发，把侦听器的格式定义为对象格式，加上immediate属性
                message: {
                    handle(newVal, oldVal) {
                        console.log(newVal, oldVal);
                    },
                    immediate: true
                },
                //让侦听器深度监听对象中每个属性的变化，把侦听器的格式定义为对象格式，加上deep属性
                user: {
                    handle(newVal, oldVal) {
                        console.log(newVal, oldVal);
                    },
                    deep: true
                }
            }
        });
    </script>
</body>

</html>